﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Dotnet.Ex.DebugViews
{
#pragma warning disable 8500
    unsafe internal sealed class IQSequenceDebugView<T> where T : struct
    {
        private readonly T* _iPtr;
        private readonly T* _qPtr;
        private readonly long _length;

        public IQSequenceDebugView(IQSpanZ<T> iqSpan)
        {

            this._iPtr = iqSpan.IDataPtr;
            this._qPtr = iqSpan.QDataPtr;
            this._length = iqSpan.LongLength;
        }

        public IQSequenceDebugView(IQUnmanagedMemoryPointer<T> pointer)
        {
            this._iPtr = pointer.IDataPtr;
            this._qPtr = pointer.QDataPtr;
            this._length = pointer.LongLength;
        }

        public IQSequenceDebugView(IQValueTypeFlexibleArray<T> arr)
        {
            IQSpanZ<T> data = arr.GetIQSpanZ();
            this._iPtr = data.IDataPtr;
            this._qPtr = data.QDataPtr;
            this._length = data.LongLength;
        }



        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
        public string[] Items
        {
            get
            {
                T* iPtr = this._iPtr;
                T* qPtr = this._qPtr;
                var array = new string[this._length];
                for (long i = 0; i < this._length; i++)
                {
                    array[i] = $"{*iPtr++},{*qPtr++}";
                }

                return array;
            }
        }
    }

}
